import Vue from 'vue'
import VueRouter from 'vue-router'
import HomePage from '../views/HomeIndex.vue'
import LoginPage from '../views/Login/LoginPage.vue'
import CommunityList from '@/views/CommunityManage/CommunityList.vue'
import PropertyManagement from '@/views/PropertyManage/PropertyManagement.vue'
import BuildingManagement from '@/views/PropertyManage/BuildingManagement.vue'
import PeopleManagement from '@/views/PeopleInfo/PeopleManagement.vue'
import VehicleManagement from '@/views/PeopleInfo/VehicleManagement.vue'
import PetManagement from '@/views/PeopleInfo/PetManagement.vue'
import ParkingSpaceManagement from '@/views/Parking/ParkingSpaceManagement.vue'
import ParkingSpaceUsage from '@/views/Parking/ParkingSpaceUsage.vue'
import PersonalSetting from '@/views/Setting/PersonalSetting.vue'
import ControlPanel from '@/views/ControlPanel/ControlPanel.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'homePage',
    component: HomePage,
    redirect: { name: 'ControlPanel' },
    children: [
        {
          path: '/community',
          name: 'CommunityList',
          component: CommunityList
        },
        {
          path: '/property',
          name: 'PropertyManagement',
          component: PropertyManagement
        },
        {
          path: '/building',
          name: 'BuildingManagement',
          component: BuildingManagement
        },
        {
          path: '/people',
          name: 'PeopleManagement',
          component: PeopleManagement
        },
        {
          path: '/vehicle',
          name: 'VehicleManagement',
          component: VehicleManagement
        },
        {
          path: '/pet',
          name: 'PetManagement',
          component: PetManagement
        },
        {
          path: '/parking',
          name: 'ParkingSpaceManagement',
          component: ParkingSpaceManagement
        },
        {
          path: '/parking',
          name: 'ParkingSpaceUsage',
          component: ParkingSpaceUsage
        },
        {
          path: '/personal',
          name: 'PersonalSettings',
          component: PersonalSetting
        },
        {
          path: '/control',
          name: 'ControlPanel',
          component: ControlPanel
        }
      ],
  },
  {
    path: '/',
    name: 'Login',
    component: LoginPage
  }

]

const router = new VueRouter({
  routes
})

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => {
    // 处理路由跳转相同路径的错误
    if (err.name === 'NavigationDuplicated') {
      return err;
    }
    // 其他错误继续抛出
    return Promise.reject(err);
  });
};

export default router